/*
 * simpleStat.cpp
 *
 *  Created on: 29-09-2011
 *      Author: pawel
 */

#include"simpleStat.h"
#include<math.h>
#include<ext/slist>
#include"../alignContainerV.h"
simpleStat::simpleStat(std::vector<int> &scoreVector)
:mean(0),stdDev(0),length(scoreVector.size())
{
data.resize(length);
	for(size_t i=0;i<length;i++){
		data[i] = scoreVector[i];
	}
	calculateStats();
}
simpleStat::simpleStat(std::valarray<int> &scoreArray)
:mean(0),stdDev(0),length(scoreArray.size()),data(scoreArray)
{
calculateStats();
}
simpleStat::simpleStat(alignContainerV *alignContainerPtr)
:mean(0),stdDev(0),length(alignContainerPtr->getScoreList().size())
{
	size_t i=0;
	data.resize(length);
	for(__gnu_cxx::slist<int>::const_iterator it= alignContainerPtr->getScoreList().begin();it != alignContainerPtr->getScoreList().end();++it){
		data[i++] = *it;
	}
	calculateStats();
}



double simpleStat::getZscore(int value)const{
	return (value-mean)/stdDev;
}
void simpleStat::calculateStats(){
	for(size_t i=0;i<length;i++){
		mean+=data[i]/(double)length;
	}
	for(size_t i=0;i<length;i++){
		stdDev+= ((data[i] - mean)*(data[i] - mean))/((double)length - 1.0);
	}
	stdDev = sqrt(stdDev);
}
double simpleStat::getMean(){
	return mean;
}
double simpleStat::getStdDev(){
	return stdDev;
}
